import {getToken} from '@/api/login'
import { setToken,removeToken } from '@/utils/storage'
import {LOGIN,LOGOUT} from '../actionTypes'

export const login = (payload)=>{
    return async dispatch =>{
        const res = await getToken(payload)
        // console.log(res)
        setToken(res.data.token)
        dispatch({
            type:LOGIN,
            payload: res.data.token
        })
    }
}

export const logout = ()=>{
    return async dispatch =>{
        removeToken()
        dispatch({
            type:LOGOUT
        })
    }
}